package fr.p10.miage.rps.model;


import org.testng.annotations.*;

import java.util.ArrayList;
import java.util.List;

import static org.testng.Assert.*;

/**
 * Created with IntelliJ IDEA.
 * User: naberrad
 * Date: 21/10/13
 * Time: 16:20
 * To change this template use File | Settings | File Templates.
 */
public class RockPaperScissorsTest {
    public RockPaperScissors rps;
    public static Player player1;
    public static Player player2;
    public static Player player3;
    public static Player player4;
    public static Player player5;
    public static Player player6;

    @BeforeClass
    public void setUp() throws Exception {

        rps = new RockPaperScissors();
    }

    @BeforeClass
    public void setUpClass() throws Exception {
        List<RPSEnum> mouvements = new ArrayList<RPSEnum>();
        for (int i = 0; i < 20; i++) {
            mouvements.add(i, RPSEnum.SCISSORS);
        }
        player1 = new Player("Joueur1", mouvements);
        player2 = new Player("Joueur2", mouvements);

        player3 = player1;
        mouvements = new ArrayList<RPSEnum>();
        for (int i = 0; i < 20; i++) {
            mouvements.add(i, RPSEnum.PAPER);
        }
        player4 = new Player("Joueur4", mouvements);

        player5 = player4;
        mouvements = new ArrayList<RPSEnum>();
        for (int i = 0; i < 20; i++) {
            mouvements.add(i, RPSEnum.SCISSORS);
        }
        player6 = new Player("Joueur6", mouvements);
    }

    @AfterClass
    public void tearDown() throws Exception {

        rps = null;

    }

    @AfterClass
    public void tearDownClass() throws Exception {
        player1 = null;
        player2 = null;
        player3 = null;
        player4 = null;
        player5 = null;
        player6 = null;
    }

    //@Parameters({"paper", "rock"})
    @Test(dataProvider = "winData")
    public void testWinPlay(RPSEnum p1, RPSEnum p2) throws Exception {
        assertEquals(rps.play(p1, p2), Result.WIN);
    }

    //@Parameters({"paper","paper"})
    @Test(dataProvider = "TieData")
    public void testTiePlay(RPSEnum p1, RPSEnum p2) throws Exception {
        assertEquals(rps.play(p1, p2), Result.TIE);
    }

    @Test(dataProvider = "LostData")
    public void testLostPlay(RPSEnum p1, RPSEnum p2) throws Exception {
        assertEquals(rps.play(p1, p2), Result.LOST);
    }

    @DataProvider(name = "winData")
    public Object[][] createWinData() {
        return new Object[][]{
                {RPSEnum.PAPER, RPSEnum.ROCK},
                {RPSEnum.ROCK, RPSEnum.SCISSORS},
                {RPSEnum.SCISSORS, RPSEnum.PAPER}
        };

    }

    @DataProvider(name = "TieData")
    public Object[][] createTieData() {
        return new Object[][]{
                {RPSEnum.PAPER, RPSEnum.PAPER},
                {RPSEnum.ROCK, RPSEnum.ROCK},
                {RPSEnum.SCISSORS, RPSEnum.SCISSORS}
        };

    }

    @DataProvider(name = "LostData")
    public Object[][] createLostData() {
        return new Object[][]{
                {RPSEnum.PAPER, RPSEnum.SCISSORS},
                {RPSEnum.ROCK, RPSEnum.PAPER},
                {RPSEnum.SCISSORS, RPSEnum.ROCK}
        };

    }

    @DataProvider(name = "playerTieData")
    public static Player[][] createPlayerTieData() {
        return new Player[][]{{player1, player2}};
    }

    @DataProvider(name = "playerWinData")
    public static Player[][] createPlayerWinData() {
        return new Player[][]{{player3, player4}};
    }

    @DataProvider(name = "playerLoseData")
    public static Player[][] createPlayerLoseData() {
        return new Player[][]{{player5, player6}};
    }

    @Test(dataProvider = "playerTieData")
    public void testTiePlay(Player p1, Player p2) {
        assertEquals(rps.play(p1, p2), Result.TIE);
    }

    @Test(dataProvider = "playerWinData")
    public void testWinPlay(Player p1, Player p2) {
        assertEquals(rps.play(p1, p2), Result.WIN);
    }

    @Test(dataProvider = "playerLoseData")
    public void testLosePlay(Player p1, Player p2) {
        assertEquals(rps.play(p1, p2), Result.LOST);
    }


}
